home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / cvs-1_3.lha / cvs-1.3 / src / remove.c < prev    next >
C/C++ Source or Header  |  1992-04-09  |  4KB  |  177 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.3 kit.
  7.  * 
  8.  * Remove a File
  9.  * 
  10.  * Removes entries from the present version. The entries will be removed from
  11.  * the RCS repository upon the next "commit".
  12.  * 
  13.  * "remove" accepts no options, only file names that are to be removed.  The
  14.  * file must not exist in the current directory for "remove" to work
  15.  * correctly.
  16.  */
  17.  
  18. #include "cvs.h"
  19.  
  20. #ifndef lint
  21. static char rcsid[] = "@(#)remove.c 1.34 92/04/10";
  22. #endif
  23.  
  24. #if __STDC__
  25. static int remove_fileproc (char *file, char *update_dir,
  26.                 char *repository, List *entries,
  27.                 List *srcfiles);
  28. static Dtype remove_dirproc (char *dir, char *repos, char *update_dir);
  29. #else
  30. static Dtype remove_dirproc ();
  31. static int remove_fileproc ();
  32. #endif
  33.  
  34. static int local;
  35. static int removed_files;
  36. static int auto_removed_files;
  37.  
  38. static char *remove_usage[] =
  39. {
  40.     "Usage: %s %s [-lR] [files...]\n",
  41.     "\t-l\tProcess this directory only (not recursive).\n",
  42.     "\t-R\tProcess directories recursively.\n",
  43.     NULL
  44. };
  45.  
  46. int
  47. cvsremove (argc, argv)
  48.     int argc;
  49.     char *argv[];
  50. {
  51.     int c, err;
  52.  
  53.     if (argc == -1)
  54.     usage (remove_usage);
  55.  
  56.     optind = 1;
  57.     while ((c = gnu_getopt (argc, argv, "lR")) != -1)
  58.     {
  59.     switch (c)
  60.     {
  61.         case 'l':
  62.         local = 1;
  63.         break;
  64.         case 'R':
  65.         local = 0;
  66.         break;
  67.         case '?':
  68.         default:
  69.         usage (remove_usage);
  70.         break;
  71.     }
  72.     }
  73.     argc -= optind;
  74.     argv += optind;
  75.  
  76.     /* start the recursion processor */
  77.     err = start_recursion (remove_fileproc, (int (*) ()) NULL, remove_dirproc,
  78.                (int (*) ()) NULL, argc, argv, local,
  79.                W_LOCAL, 0, 1, (char *) NULL, 1);
  80.  
  81.     if (removed_files)
  82.     error (0, 0, "use '%s commit' to remove %s permanently", program_name,
  83.            (removed_files == 1) ? "this file" : "these files");
  84.     else
  85.     if (!auto_removed_files)
  86.         error (0, 0, "no files removed; use `%s' to remove the file first",
  87.            RM);
  88.  
  89.     return (err);
  90. }
  91.  
  92. /*
  93.  * remove the file, only if it has already been physically removed
  94.  */
  95. /* ARGSUSED */
  96. static int
  97. remove_fileproc (file, update_dir, repository, entries, srcfiles)
  98.     char *file;
  99.     char *update_dir;
  100.     char *repository;
  101.     List *entries;
  102.     List *srcfiles;
  103. {
  104.     char fname[PATH_MAX];
  105.     Vers_TS *vers;
  106.  
  107.     vers = Version_TS (repository, (char *) NULL, (char *) NULL, (char *) NULL,
  108.                file, 0, 0, entries, srcfiles);
  109.  
  110.     if (vers->ts_user != NULL)
  111.     {
  112.     freevers_ts (&vers);
  113.     return (0);
  114.     }
  115.  
  116.     if (vers->vn_user == NULL)
  117.     {
  118.     if (!quiet)
  119.         error (0, 0, "nothing known about %s", file);
  120.     freevers_ts (&vers);
  121.     return (0);
  122.     }
  123.  
  124.     if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
  125.     {
  126.     /*
  127.      * It's a file that has been added, but not commited yet. So,
  128.      * remove the ,p and ,t file for it and scratch it from the
  129.      * entries file.
  130.      */
  131.     Scratch_Entry (entries, file);
  132.     (void) sprintf (fname, "%s/%s%s", CVSADM, file, CVSEXT_OPT);
  133.     (void) unlink_file (fname);
  134.     (void) sprintf (fname, "%s/%s%s", CVSADM, file, CVSEXT_LOG);
  135.     (void) unlink_file (fname);
  136.     if (!quiet)
  137.         error (0, 0, "removed `%s'.", file);
  138.     auto_removed_files++;
  139.     }
  140.     else if (vers->vn_user[0] == '-')
  141.     {
  142.     freevers_ts (&vers);
  143.     return (0);
  144.     }
  145.     else
  146.     {
  147.     /* Re-register it with a negative version number.  */
  148.     (void) strcpy (fname, "-");
  149.     (void) strcat (fname, vers->vn_user);
  150.     Register (entries, file, fname, vers->ts_rcs, vers->options,
  151.           vers->tag, vers->date);
  152.     if (!quiet)
  153.     {
  154.         error (0, 0, "scheduling %s for removal", file);
  155.         removed_files++;
  156.     }
  157.     }
  158.  
  159.     freevers_ts (&vers);
  160.     return (0);
  161. }
  162.  
  163. /*
  164.  * Print a warm fuzzy message
  165.  */
  166. /* ARGSUSED */
  167. static Dtype
  168. remove_dirproc (dir, repos, update_dir)
  169.     char *dir;
  170.     char *repos;
  171.     char *update_dir;
  172. {
  173.     if (!quiet)
  174.     error (0, 0, "Removing %s", update_dir);
  175.     return (R_PROCESS);
  176. }
  177.